﻿namespace MakeVSProject4FFmpeg
{
    #region using directives
    using System;
    using System.IO;
    #endregion

    class Program
    {
        static int Main(string[] args)
        {
            CmdLineOptions options = new CmdLineOptions();
            bool b = options.ParseCmdLine(args);
            if (b == false)
            {
                return -1;
            }

            MakeFileLoader loader = new MakeFileLoader();
            loader.ParseFile(options.MakeFileOutput);
            if (options.ParseDependencies)
            {
                loader.ParseDependencies(options.GetDistributionFolderOrCurrentDir());
            }

            if (options.EnableX264)
            {
                loader.AddX264(options.LibX264Folder);
            }

            if (options.EnableZLib)
            {
                loader.AddZlib(options.LibZLibFolder);
            }

            GenProject genProj = new GenProject(
                                            new ProjectOptions(
                                                        options.ProjectName,
                                                        Guid.NewGuid(),
                                                        true,
                                                        true));

            string fileNameVCXPROJ = options.ProjectName + ".vcxproj";
            string fileNameVCXPROJFILTERS = options.ProjectName + ".vcxproj.filters";
            if (!string.IsNullOrEmpty(options.OutputFolder))
            {
                fileNameVCXPROJ = Path.Combine(options.OutputFolder, fileNameVCXPROJ);
                fileNameVCXPROJFILTERS = Path.Combine(options.OutputFolder, fileNameVCXPROJFILTERS);
            }

            using (FileStream fs = File.Create(fileNameVCXPROJ))
            {
                genProj.WriteProject(loader, fs);
            }

            using (FileStream fs = File.Create(fileNameVCXPROJFILTERS))
            {
                genProj.WriteProjectFilters(loader, fs);
            }

            return 0;
        }
    }
}
